#ifndef __CMDOP_H__
#define __CMDOP_H__

#include "vector.h"

#define VECTOR_MATCHVEC_SIZE 10
#define CMD_ARGC_MAX   25

enum
{
    CMD_SUCCESS, 
    CMD_WARNING,              
    CMD_ERR_NO_MATCH, 
    CMD_ERR_AMBIGUOUS,
    CMD_ERR_INCOMPLETE, 
    CMD_ERR_EXEED_ARGC_MAX, 
    CMD_ERR_NOTHING_TODO,   
    CMD_COMPLETE_FULL_MATCH, 
    CMD_COMPLETE_MATCH, 
    CMD_COMPLETE_LIST_MATCH, 
};

typedef struct cmd_vty_
{
    enum {VTY_NORMAL, VTY_CLOSE} status;
    vector topvec; //命令行视图
    int node; 
    int reserve;
    void *user_data;
} cmd_vty_t;

typedef struct cmd_node_
{
    int node;
    char prompt[ARRARY_SIZE_24];
    vector cmdvec;
} cmd_node_t;

typedef struct cmd_element_
{
    char *string;
    char *doc;
    vector strvec;
    int (*exec)(cmd_vty_t *, int, char **); 
    //int (*load)(cmd_vty_t *, int, char **); 
    //int (*save)(cmd_vty_t *, int, char **); 
    //int (*log)(cmd_vty_t *, int, char **); 
} cmd_element_t;

char *cmd_prompt(cmd_vty_t *vty);
void cmd_vty_init(cmd_vty_t *vty);
void cmd_free_strvec (vector v);
//static int cmd_unique_string(vector v, char *str);
//static vector cmd_make_descvec(char *string);
vector cmd_make_strvec(char *string);
//static int cmd_filter_by_completion (char *string, vector v, int index);
char **cmd_complete_command (vector vline, cmd_vty_t *vty, int *status);
int cmd_execute_command(vector vline, cmd_vty_t *vty);
void cmd_execute(cmd_vty_t *vty, char *line);
void cmd_doc_print(cmd_vty_t *vty, FILE *fp);
void cmd_install_node(cmd_vty_t *vty, cmd_node_t *node);
void cmd_install_element(vector topvec, int ntype, cmd_element_t *cmd);

#endif
